package diamondServer.businesslogic.resource;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * A thread safe repository of resources.
 */
public class DefaultResRepository
	implements ResourcesRepository
{
	private Map<String,Resource> mResources;
	
	private static DefaultResRepository instance = new DefaultResRepository();
	
	private DefaultResRepository()
	{
		mResources = new ConcurrentHashMap<String, Resource>();
	}
	
	public static DefaultResRepository getInstance(){
		return instance;
	}
	
	@Override
	public void addResource(String resName, Resource res){
		mResources.put(resName, res);
	}
	
	@Override
	public Resource getResource(String resName){
		return mResources.get(resName);
	}
	
	@Override
	public void removeResource(String resName){
		mResources.remove(resName);
	}
	
	@Override
	public void removeAll()
	{
		mResources.clear();
	}
}
